import time

import schedule
import win32gui
from pynput import keyboard
from utils.diabloUtils import Diablo


pause = False
fight=False

window_title = "暗黑破坏神III"  # 替换为目标窗口标题
hwnd = win32gui.FindWindow(None, window_title)
if not hwnd:
    print("暗黑破坏神III未运行！")
    input()
    exit(1)

diablo = Diablo(hwnd)

def on_press(key):
    try:
        print(f'字母键 {key.char} 被按下')
        if key.char=='5':
            global  fight
            fight=not fight

    except AttributeError:

        if str(key) == "Key.space":
            print("开始或暂停 ")
            global pause
            pause = not pause

        print(f'特殊键 {key} 被按下')


def on_release(key):
    print(f'{key} 被释放')



if __name__ == "__main__":


    # 监听键盘事件
    listener=keyboard.Listener(
            on_press=on_press,
            on_release=on_release,
    daemon=True)
    listener.start()

    schedule.every(4).seconds.do(diablo.three)
    schedule.every(2).seconds.do(diablo.four)
    schedule.every(0.5).seconds.do(diablo.click_at_current_position)
    schedule.every(30).seconds.do(diablo.Q)
    schedule.every(10).seconds.do(diablo.ButtonRight)
    def one():
        if fight:
            diablo.one()

    def ButtonLetf():
        if fight:
            diablo.ButtonLetf()

    schedule.every(3).seconds.do(one)
    schedule.every(0.5).seconds.do(ButtonLetf)

    while True:
        if pause:
            schedule.run_pending()
        time.sleep(0.5)

    input()